<template>
  <!-- 路由 -->
  <div>
    <Row class="powersupply_tag" type="flex" align="middle">
      <Tag
        v-for="item in value"
        :key="item.name"
        type="dot"
        closable
        color="blue"
        :class="routerTitle==item.name?'routerY':'routerN'"
        @on-close="closeTag(item)"
        @click.native="openTag(item)"
      >{{item.title}}</Tag>
    </Row>
  </div>
</template>

<script>
import { type } from "os";
import { deflate } from "zlib";
export default {
  props: {
    value: {
      type: Array,
      default: []
    },
    routerCurrent: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      routerTitle: this.routerCurrent
    };
  },
  computed: {},
  watch: {
    routerTitle(puthName) {
      this.$router.push({
        name: puthName
      });
    },
    value(Array) {
      window.sessionStorage.setItem("routerList", JSON.stringify(Array));
    }
  },
  methods: {
    closeTag(object) {
      let reset = false;
      if (object.name == this.routerTitle) {
        reset = true;
      }
      this.value.forEach((item, index) => {
        if (item.name == object.name) {
          this.value.splice(index, 1);
          return false;
        }
      });
      if (reset) {
        this.routerTitle = this.value[0].name;
      }
      window.sessionStorage.setItem("routerList", JSON.stringify(this.value));
    },
    openTag(object) {
      this.routerTitle = object.name;
    }
  },
  created() {
    window.sessionStorage.setItem("routerList", JSON.stringify(this.value));
  },
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {} // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' >
.powersupply_tag {
  width: 100%;
  height: 60px;
  padding: 0px 20px;
  background-color: white;
  position: relative;
}

.routerY {
  color: #1890ff !important;
  user-select: none;
  .ivu-tag-dot-inner {
    background-color: #1890ff !important;
  }
}

.routerN {
  color: #cccccc !important;
  user-select: none;
  .ivu-tag-dot-inner {
    background-color: #cccccc !important;
  }
}

.ivu-tag-blue .ivu-tag-text {
  color: inherit !important;
}
</style>
